package com.todod.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.todod.entity.ResultData;
import com.todod.model.Menu;
import com.todod.service.IMenuService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gsh
 * @since 2020-11-16
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

	@Autowired
	private IMenuService iMenuService;

	@GetMapping("/list")
	public ResultData getList() {
		List<Menu> list = iMenuService.getList();
		return ResultData.success("ok", list);
	}

	/**
	 * 
	 * @param _userId
	 * @param menu
	 * @return
	 */
	@PostMapping("/save")
	public ResultData save(@RequestAttribute Long _userId, @RequestBody Menu menu) {
		iMenuService.saveData(_userId, menu);
		return ResultData.success("ok");
	}

	/**
	 * 
	 * @param _userId
	 * @param id
	 * @return
	 */
	@PostMapping("/detete")
	public ResultData detete(@RequestAttribute Long _userId, Long id) {
		iMenuService.delete(_userId, id);
		return ResultData.success("ok");
	}

	@RequestMapping("/geTmeunListBydepartid")
	public ResultData geTmeunListBydepartid() {
		QueryWrapper<Menu> queryWrapper = new QueryWrapper<>();
		List<Menu> list = iMenuService.list(queryWrapper);
		return ResultData.success("ok", list);
	}

}
